<?php

/**
 * This is the model class for table "tb_brand_details".
 *
 * The followings are the available columns in table 'tb_brand_details':
 * @property integer $brand_id
 * @property string $brand_details
 * @property string $brand_email
 * @property string $created_by
 * @property string $created_date
 * @property string $updated_by
 * @property string $updated_date
 * 
 *
 * The followings are the available model relations:
 * @property TbBrand $brand
 */
class BrandDetails extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return BrandDetails the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tb_brand_details';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('brand_id', 'numerical', 'integerOnly'=>true),
			array('brand_email', 'length', 'max'=>100),
			array('created_by, updated_by', 'length', 'max'=>20),
			array('brand_details, created_date, updated_date', 'safe'),
            
            array('created_date', 'default',
                'value' => new CDbExpression('NOW()'),
                'setOnEmpty' => false, 'on' => 'insert'),
            array('updated_date', 'default',
                'value' => new CDbExpression('NOW()'),
                'setOnEmpty' => false, 'on' => 'insert'),
            array('updated_date', 'default',
                'value' => new CDbExpression('NOW()'),
                'setOnEmpty' => false, 'on' => 'update'),
                
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('brand_id, brand_email, created_by, created_date, updated_by, updated_date', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'brand' => array(self::BELONGS_TO, 'TbBrand', 'brand_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'brand_id' => 'Brand',
            'brand_name' => 'Brand Name',
			'brand_details' => 'Brand Details',
			'brand_email' => 'Brand Email',
			'created_by' => 'Created By',
			'created_date' => 'Created Date',
			'updated_by' => 'Updated By',
			'updated_date' => 'Updated Date',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('t.brand_id',$this->brand_id);
		/*$criteria->compare('brand_details',$this->brand_details,true);    */
		$criteria->compare('t.brand_email',$this->brand_email,true);
		$criteria->compare('t.created_by',$this->created_by,true);
		$criteria->compare('t.created_date',$this->created_date,true);
		$criteria->compare('t.updated_by',$this->updated_by,true);
		$criteria->compare('t.updated_date',$this->updated_date,true);
        $criteria->join = ' inner join tb_brand b on (t.brand_id = b.brand_id) ';

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
            
		));
	}
}
